package com.qckj.amz.controller;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.enums.BusinessType;
import com.qckj.amz.domain.ConfigCategory;
import com.qckj.amz.service.IConfigCategoryService;
import com.qckj.common.utils.poi.ExcelUtil;
import com.qckj.common.core.page.TableDataInfo;

import java.util.Arrays;
import java.util.List;

/**
 * 产品类别配置Controller
 *
 * @author luchuan
 * @since 1.0 2023-01-19
 */
@RestController
@RequestMapping("/amz/configCategory")
public class ConfigCategoryController extends BaseController {
    @Autowired
    private IConfigCategoryService configCategoryService;

    /**
     * 查询产品类别配置列表
     */
    @PreAuthorize("@ss.hasPermi('amz:configCategory:list')")
    @GetMapping("/list")
    public TableDataInfo list(ConfigCategory configCategory) {
        Page<ConfigCategory> page = configCategoryService.findConfigCategoryPage(configCategory);
        return getDataTable(page);
    }

    /**
     * 导出产品类别配置列表
     */
    @PreAuthorize("@ss.hasPermi('amz:configCategory:export')")
    @Log(title = "产品类别配置", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ConfigCategory configCategory) {
        List<ConfigCategory> list = configCategoryService.findConfigCategoryList(configCategory);
        ExcelUtil<ConfigCategory> util = new ExcelUtil<>(ConfigCategory.class);
        return util.exportExcel(list, "configCategory");
    }

    /**
     * 获取产品类别配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:configCategory:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(configCategoryService.findById(id));
    }

    /**
     * 新增产品类别配置
     */
    @PreAuthorize("@ss.hasPermi('amz:configCategory:add')")
    @Log(title = "产品类别配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ConfigCategory configCategory) {
        AjaxResult result = configCategoryService.save(configCategory);
        return result;
    }

    /**
     * 修改产品类别配置
     */
    @PreAuthorize("@ss.hasPermi('amz:configCategory:edit')")
    @Log(title = "产品类别配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ConfigCategory configCategory) {
        AjaxResult result = configCategoryService.edit(configCategory);
        return result;
    }

    /**
     * 删除产品类别配置
     */
    @PreAuthorize("@ss.hasPermi('amz:configCategory:remove')")
    @Log(title = "产品类别配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        configCategoryService.deleteByIds(Arrays.asList(ids));
        return AjaxResult.success();
    }

    /**
     * 通过当前所属部门获取类目列表
     * @return
     */
    @PostMapping("/getConfigCategoryByDept")
    public AjaxResult getConfigCategoryByDept() {
        AjaxResult res = configCategoryService.getConfigCategoryByDept();
        return res;
    }

}
